//
//  CHTextView.swift
//  jyzx
//
//  Created by cyptt on 2022/6/6.
//

import UIKit

extension UITextView {

   
    /*
     间距
     @lineH 间距
     @textColor 字体颜色
     @font 字体
     */
    public func setLineH(lineH:CGFloat = 10,textColor:UIColor = UIColor.init(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 51/255.0),font:UIFont = UIFont.systemFont(ofSize: 14),firstLineHeadIndent:CGFloat = 0,keyKern:CGFloat? = nil){
        
        let mutAttString:NSMutableAttributedString = NSMutableAttributedString.init(string: self.text)

        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = lineH
        paragraphStyle.firstLineHeadIndent = firstLineHeadIndent
        
        mutAttString.addAttributes([NSAttributedString.Key.paragraphStyle:paragraphStyle,NSAttributedString.Key.foregroundColor:textColor,NSAttributedString.Key.font:font], range: NSMakeRange(0, mutAttString.length))
        
        if keyKern != nil{
            mutAttString.addAttributes(
                [
                    NSAttributedString.Key.kern:keyKern!
                ], range: NSMakeRange(0, mutAttString.length))
        }
    
        self.attributedText = mutAttString;
    }

}
